package com.ch.forum.service.impl;

import com.ch.forum.constants.GateIoConstants;
import com.ch.forum.service.IStockRestApi;
import com.ch.forum.service.SystemParamService;
import com.ch.forum.utils.HttpUtilManager;
import org.apache.http.HttpException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class StockRestApi implements IStockRestApi {

	@Autowired
	private SystemParamService systemParamService;


	@Override
	public String marketlist() throws HttpException, IOException {
		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
		String param = "";
		String result = httpUtil.requestHttpGet(systemParamService.findValueByName("gateio"), GateIoConstants.MARKETLIST_URL, param);
		return result;
	}

	@Override
	public String ticker(String symbol) throws HttpException, IOException {
		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
		String param = "";

		param += "/"+symbol;

		String result = httpUtil.requestHttpGet(systemParamService.findValueByName("gateio"), GateIoConstants.TICKER_URL + param, "");
		return result;
	}


//	@Override
//	public String pairs() throws HttpException, IOException {
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String param = "";
//		String result = httpUtil.requestHttpGet(url_prex, PAIRS_URL, param);
//	    return result;
//	}
//
//	@Override
//	public String marketinfo() throws HttpException, IOException {
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String param = "";
//		String result = httpUtil.requestHttpGet(url_prex, MARKETINFO_URL, param);
//		return result;
//	}
//
//	@Override
//	public String tickers() throws HttpException, IOException {
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String param = "";
//		String result = httpUtil.requestHttpGet(url_prex, TICKERS_URL, param);
//		return result;
//	}
//
//	@Override
//	public String orderBook(String symbol) throws HttpException, IOException {
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String param = "";
//		if(!StringUtil.isEmpty(symbol )) {
//			if(param.equals("")) {
//				param += "/";
//			}
//			param += symbol;
//		}
//		String result = httpUtil.requestHttpGet(url_prex, ORDERBOOK_URL + param, param);
//		return result;
//	}
//
//	@Override
//	public String tradeHistory(String symbol) throws HttpException, IOException {
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String param = "";
//		if(!StringUtil.isEmpty(symbol )) {
//			if(param.equals("")) {
//				param += "/";
//			}
//			param += symbol;
//		}
//		System.out.println(TRADEHISTORY_URL+param);
//		String result = httpUtil.requestHttpGet(url_prex, TRADEHISTORY_URL + param, "");
//		return result;
//	}
//
//	@Override
//	public String balance() throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//
//		String result = httpUtil.doRequest( "data", "post", url_prex+BALANCE_URL, params );
//		return result;
//	}
//
//
//	@Override
//	public String depositAddress(String symbol) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+DEPOSITADDRESS_URL, params );
//		return result;
//	}
//
//
//	@Override
//	public String depositsWithdrawals(String startTime, String endTime) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("start", startTime);
//		params.put("end", endTime);
//
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ DEPOSITESWITHDRAWALS_URL, params );
//		return result;
//	}
//
//	@Override
//	public String buy(String currencyPair, String rate, String amount) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("currencyPair", currencyPair);
//		params.put("rate", rate);
//		params.put("amount", amount);
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ BUY_URL, params );
//		return result;
//	}
//
//	@Override
//	public String sell(String currencyPair, String rate, String amount) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("currencyPair", currencyPair);
//		params.put("rate", rate);
//		params.put("amount", amount);
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ SELL_URL, params );
//		return result;
//	}
//
//
//	@Override
//	public String cancelOrder(String orderNumber, String currencyPair) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("orderNumber", orderNumber);
//		params.put("currencyPair", currencyPair);
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ CANCELORDER_URL, params );
//		return result;
//	}
//
//	@Override
//	public String cancelAllOrders(String type, String currencyPair) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("type", type);
//		params.put("currencyPair", currencyPair);
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ CANCELALLORDERS_URL, params );
//		return result;
//	}
//
//	@Override
//	public String getOrder(String orderNumber, String currencyPair) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("orderNumber", orderNumber);
//		params.put("currencyPair", currencyPair);
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ GETORDER_URL, params );
//		return result;
//	}
//
//
//	@Override
//	public String openOrders() throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ OPENORDERS_URL, params );
//		return result;
//	}
//
//
//	@Override
//	public String myTradeHistory(String currencyPair, String orderNumber) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("currencyPair", currencyPair);
//		params.put("orderNumber", orderNumber);
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ MYTRADEHISTORY_URL, params );
//		return result;
//	}
//
//
//	@Override
//	public String withdraw(String currency, String amount, String address) throws HttpException, IOException {
//		Map<String, String> params = new HashMap<String, String>();
//		params.put("currency", currency);
//		params.put("amount", amount);
//		params.put("address", address);
//
//		HttpUtilManager httpUtil = HttpUtilManager.getInstance();
//		String result = httpUtil.doRequest( "data", "post", url_prex+ WITHDRAW_URL, params );
//		return result;
//	}

//	public static void main(String[] args) {
//		String query_url = "https://data.gateio.io";
//		String trade_url = "https://api.gateio.io";
//
//		IStockRestApi api = new StockRestApi(trade_url);
//		try {
//			System.out.println(api.marketlist());
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}

}
